package com.umakr.ax.security.web;

import com.umakr.ax.security.model.Role;
import com.umakr.ax.security.model.vo.RoleVO;
import com.umakr.ax.security.service.RoleService;
import com.umakr.ax.security.service.UserRoleService;
import com.umakr.ax.security.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author gx
 * @since 2017/5/15
 */
@Controller
@RequestMapping("/api/system/role")
public class PermissionRoleController {
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;
    @Autowired
    UserRoleService userRoleService;




    /**
     * (H-F)19
     * 新增角色信息
     * @param roleVO 角色信息
     * @return 操作是否成功
     */
    @ApiOperation("新增角色信息")
    @RequestMapping("/addRole")
    @ResponseBody
    public Object addRole(RoleVO roleVO){
        roleService.update(roleVO.toRole());
        return roleService.resultMap(1,"");
    }


    /**
     * (H-F)20
     * 更新角色信息
     * @param roleVO 角色信息
     * @return 操作是否成功
     */
    @ApiOperation("更新角色信息")
    @RequestMapping("/roleUpdate")
    @ResponseBody
    public Object roleUpdate(RoleVO roleVO){
        if(roleVO.getRoleId() != null){
            Role roleOld  = roleService.selectById(roleVO.getRoleId());
            BeanUtils.copyProperties(roleVO.toRole(),roleOld);
            roleService.update(roleOld);
        }else{
            return roleService.resultMap(0,"角色id不能为null.");
        }
        return roleService.resultMap(1,"");
    }

}
